package mil.af.amc.adpetracker.web.actions.struts1.ItemModel;

import mil.af.amc.adpetracker.service.ItemModelService;
import org.apache.struts.action.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.HashMap;

/**
 * Action To Create an EquipmentItem
 *
 * This action should only be used in an Ajax context, since execute() returns
 * null, and it looks for GET parameters rather than POST attributes
 *
 * @author TSgt Jason Ferguson
 */

public class CreateModelAction extends Action {

    private ItemModelService itemModelService;

    public void setItemModelService(ItemModelService itemModelService) {
        this.itemModelService = itemModelService;
    }

    @Override
    @SuppressWarnings({"unchecked"})
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {

        //DynaActionForm itemForm = (DynaActionForm) form;

        Map itemMap = new HashMap();

        Integer manufacturerId = Integer.parseInt(request.getParameter("manufacturerId"));
        itemMap.put("manufacturerId", manufacturerId);

        Integer equipmentTypeId = Integer.parseInt(request.getParameter("equipmentTypeId"));
        itemMap.put("equipmentTypeId", equipmentTypeId);

        itemMap.put("modelName", request.getParameter("modelName"));

        Integer processorSpeed = Integer.parseInt(request.getParameter("processorSpeed"));
        itemMap.put("processorSpeed", processorSpeed);

        Integer screenSize = Integer.parseInt(request.getParameter("screenSize"));
        itemMap.put("screenSize", screenSize);
        
        itemModelService.createModel(itemMap);

        return null;

    }
}
